
/** 
 * @file		ENC28J60.h
 * @brief				
 * @details	Project	: BHS-Ethernet 
 * 
 * 
 * @author	Seven Zeng
 * @date		30/11/2019
 * @copyright	MICC Tech All rights reserved
 * 
 ************************************************************** 
 * @par
 * 
 * 
 ************************************************************** 
 */
 
 
#ifndef __ENC28J60_H__
#define __ENC28J60_H__


//===============================INCLUDE==========================

#include "porting.h"
//================================================================


#ifdef __cplusplus
extern "C" {
#endif // #ifdef __cplusplus  



//=========================TYPE DEFINITIONS=======================


//================================================================




//=========================CONST DEFINITIONS======================
typedef enum {
	BANK0_ERDPTL,
	BANK0_ERDPTH,
	BANK0_EWRPTL,
	BANK0_EWRPTH,
	BANK0_ETXSTL,
	BANK0_ETXSTH,
	BANK0_ETXNDL,
	BANK0_ETXNDH,
	BANK0_ERXSTL,
	BANK0_ERXSTH,
	BANK0_ERXNDL,
	BANK0_ERXNDH,
	BANK0_ERXRDPTL,
	BANK0_ERXRDPTH,
	BANK0_ERXWRPTL,
	BANK0_ERXWRPTH,
	BANK0_EDMASTL,
	BANK0_EDMASTH,
	BANK0_EDMANDL,
	BANK0_EDMANDH,
	BANK0_EDMADSTL,
	BANK0_EDMADSTH,
	BANK0_EDMACSL,
	BANK0_EDMACSH,
	BANK0_RSVD0,
	BANK0_RSVD1,
	BANK0_Reserved,
	BANK0_EIE,
	BANK0_EIR,
	BANK0_ESTAT,
	BANK0_ECON2,
	BANK0_ECON1,
} E_BANK0;

typedef enum {
	BANK1_EHT0,
	BANK1_EHT1,
	BANK1_EHT2,
	BANK1_EHT3,
	BANK1_EHT4,
	BANK1_EHT5,
	BANK1_EHT6,
	BANK1_EHT7,
	BANK1_EPMM0,
	BANK1_EPMM1,
	BANK1_EPMM2,
	BANK1_EPMM3,
	BANK1_EPMM4,
	BANK1_EPMM5,
	BANK1_EPMM6,
	BANK1_EPMM7,
	BANK1_EPMCSL,
	BANK1_EPMCSH,
	BANK1_RSVD0,
	BANK1_RSVD1,
	BANK1_EPMOL,
	BANK1_EPMOH,
	BANK1_Reserved,
	BANK1_Reserved1,
	BANK1_ERXFCON,
	BANK1_EPKTCNT,
	BANK1_Reserved2,
	BANK1_EIE,
	BANK1_EIR,
	BANK1_ESTAT,
	BANK1_ECON2,
	BANK1_ECON1,
} E_BANK1;

typedef enum {
	BANK2_MACON1,
	BANK2_Reserved,
	BANK2_MACON3,
	BANK2_MACON4,
	BANK2_MABBIPG,
	BANK2_RSVD0,
	BANK2_MAIPGL,
	BANK2_MAIPGH,
	BANK2_MACLCON1,
	BANK2_MACLCON2,
	BANK2_MAMXFLL,
	BANK2_MAMXFLH,
	BANK2_Reserved0,
	BANK2_Reserved1,
	BANK2_Reserved2,
	BANK2_RSVD1,
	BANK2_Reserved3,
	BANK2_Reserved4,
	BANK2_MICMD,
	BANK2_RSVD2,
	BANK2_MIREGADR,
	BANK2_Reserved5,
	BANK2_MIWRL,
	BANK2_MIWRH,
	BANK2_MIRDL,
	BANK2_MIRDH,
	BANK2_Reserved6,
	BANK2_EIE,
	BANK2_EIR,
	BANK2_ESTAT,
	BANK2_ECON2,
	BANK2_ECON1,
} E_BANK2;

typedef enum {
	BANK3_MAADR5,
	BANK3_MAADR6,
	BANK3_MAADR3,
	BANK3_MAADR4,
	BANK3_MAADR1,
	BANK3_MAADR2,
	BANK3_EBSTSD,
	BANK3_EBSTCON,
	BANK3_EBSTCSL,
	BANK3_EBSTCSH,
	BANK3_MISTAT,
	BANK3_RSVD0,
	BANK3_RSVD1,
	BANK3_RSVD2,
	BANK3_RSVD3,
	BANK3_RSVD4,
	BANK3_RSVD5,
	BANK3_RSVD6,
	BANK3_EREVID,
	BANK3_RSVD7,
	BANK3_RSVD8,
	BANK3_ECOCON,
	BANK3_Reserved,
	BANK3_EFLOCON,
	BANK3_EPAUSL,
	BANK3_EPAUSH,
	BANK3_Reserved1,
	BANK3_EIE,
	BANK3_EIR,
	BANK3_ESTAT,
	BANK3_ECON2,
	BANK3_ECON1,
} E_BANK3;

typedef enum {
	PHCON1,
	PHSTAT1,
	PHID1,
	PHID2,
	PHCON2 = 0X10,
	PHSTAT2,
	PHIE,
	PHIR,
	PHLCON
} E_PHY_REG_ADDR;

typedef union {
	u8 bytes[6];
	struct {
		u8 nextPackPointerLo;
		u8 nextPackPointerHi;
		u8 byteCountLo;
		u8 byteCountHi;
		union {
			u8 all;
			struct {
				u8 long_dropEvent	: 1;
				u8 rsvd0			: 1;
				u8 carrierEvent		: 1;
				u8 rsvd1			: 1;
				u8 crcErr			: 1;
				u8 lengthErr		: 1;
				u8 lengthExceed		: 1;
				u8 recieveOK		: 1;
			} bit;
		} statusVector2;
		union {
			u8 all;
			struct {
				u8 multiCast		: 1;
				u8 broadCast		: 1;
				u8 dribbleNibble	: 1;
				u8 controlFrame		: 1;
				u8 pauseFrame		: 1;
				u8 opCodeUnkown		: 1;
				u8 vlan				: 1;
				u8 zero				: 1;
			} bit;
		} statusVector3;
	} bits;
} T_PACK_HEADER;

typedef struct {
	T_PACK_HEADER header;
	u8 data[1518];
} T_ETH_PACK;

//================================================================




//=========================VARIABLE DECLARATIONS==================

//#ifdef ENC28J60_DEF
//#define _ENC28J60_DEF
//#else
//#define _ENC28J60_DEF extern
//#endif
//_ENC28J60_DEF 
//_ENC28J60_DEF 



//================================================================




//=========================ROUTINE PROTOTYPES=====================
void ENC28J60_Init (void);
void ENC28J60_SetBank(u8 bank);
u8 ENC28J60_ReadEthControlRegister(u8 address);
u8 ENC28J60_ReadMACOrMIIControlRegister(u8 address);
void ENC28J60_WriteControlRegister (u8 address, u8 value);
void ENC28J60_ReadBuffer(/*u8 startAddrLo, u8 startAddrHi, */u8* pDest, u16 count);
void ENC28J60_WriteBuffer(u16 startAddr, u8* pSrc, u16 count);
void ENC28J60_SetEthBits(u8 address, u8 bitMask);
void ENC28J60_ResetEthBits(u8 address, u8 bitMask);
void ENC28J60_Reset(void);
u16 ENC28J60_ReadPHYRegister(u8 PHYaddr);
void ENC28J60_WritePHYRegister(u8 PHYaddr, u16 value);

//================================================================




#ifdef __cplusplus
}
#endif // #ifdef __cplusplus  



#endif // __ENC28J60_H__ 
 


